package action.chap2;

import java.util.Arrays;
import java.util.List;

public class FilteringApples2 {
    public static void main(String[] args) {
        List<Apple> inventory = Arrays.asList(new Apple(80, "green"), new Apple(155, "green"), new Apple(120, "red"));

        prettyPrintApple(inventory, a -> null);
    }

    public class AppleFancyFormatter implements AppleFormatter{
        @Override
        public String accept(Apple apple){
            String characteristic = apple.getWeight() > 150 ? "heavy" :
                    "light";
            return "A " + characteristic +
                    " " + apple.getColor() +" apple";
        }

    }
    public class AppleSimpleFormatter implements AppleFormatter{
        public String accept(Apple apple){
            return "An apple of " + apple.getWeight() + "g";
        }
    }
    public static class Apple {
        private int weight = 0;
        private String color = "";

        public Apple(int weight, String color) {
            this.weight = weight;
            this.color = color;
        }

        public Integer getWeight() {
            return weight;
        }

        public void setWeight(Integer weight) {
            this.weight = weight;
        }

        public String getColor() {
            return color;
        }

        public void setColor(String color) {
            this.color = color;
        }

        public String toString() {
            return "Apple{" +
                    "color='" + color + '\'' +
                    ", weight=" + weight +
                    '}';
        }
    }

    public static  void prettyPrintApple(List<Apple> inventory, AppleFormatter a) {
        for (Apple apple : inventory) {
            String output = a.accept(apple);
            System.out.println(output);
        }
    }

    public interface AppleFormatter {
         String accept(Apple a);
    }
}
